package com.tsystems.tuni.sportplanet.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Location Entity.
 * 
 * @author Yuriy Eremin
 * 
 */
@Entity
@Table(name = "location", catalog = "sportsplanet", uniqueConstraints = {
		@UniqueConstraint(columnNames = "postal_code"),
		@UniqueConstraint(columnNames = "country_name") })
public class Location implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer locationId;
	private String streetAddress;
	private String postalCode;
	private String city;
	private String stateProvince;
	private String countryName;
	private Set<Game> games = new HashSet<Game>(0);
	private Set<Department> departments = new HashSet<Department>(0);

	public Location() {
	}

	public Location(String streetAddress, String postalCode, String city,
			String stateProvince, String countryName) {
		this.streetAddress = streetAddress;
		this.postalCode = postalCode;
		this.city = city;
		this.stateProvince = stateProvince;
		this.countryName = countryName;
	}

	public Location(String streetAddress, String postalCode, String city,
			String stateProvince, String countryName, Set<Game> games,
			Set<Department> departments) {
		this.streetAddress = streetAddress;
		this.postalCode = postalCode;
		this.city = city;
		this.stateProvince = stateProvince;
		this.countryName = countryName;
		this.games = games;
		this.departments = departments;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "location_id", unique = true, nullable = false)
	// @XmlID
	// @XmlJavaTypeAdapter(value = IntegerAdapter.class, type = String.class)
	public Integer getLocationId() {
		return this.locationId;
	}

	public void setLocationId(Integer locationId) {
		this.locationId = locationId;
	}

	@Column(name = "street_address", nullable = false, length = 45)
	public String getStreetAddress() {
		return this.streetAddress;
	}

	public void setStreetAddress(String streetAddress) {
		this.streetAddress = streetAddress;
	}

	@Column(name = "postal_code", unique = true, nullable = false, length = 6)
	public String getPostalCode() {
		return this.postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	@Column(name = "city", nullable = false, length = 20)
	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	@Column(name = "state_province", nullable = false, length = 40)
	public String getStateProvince() {
		return this.stateProvince;
	}

	public void setStateProvince(String stateProvince) {
		this.stateProvince = stateProvince;
	}

	@Column(name = "country_name", unique = true, nullable = false, length = 45)
	public String getCountryName() {
		return this.countryName;
	}

	public void setCountryName(String countryName) {
		this.countryName = countryName;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "location")
	// @XmlIDREF
	@XmlTransient
	public Set<Game> getGames() {
		return this.games;
	}

	public void setGames(Set<Game> games) {
		this.games = games;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "location")
	@XmlTransient
	public Set<Department> getDepartments() {
		return this.departments;
	}

	public void setDepartments(Set<Department> departments) {
		this.departments = departments;
	}

	@Override
	public String toString() {
		return "com.tsystems.tuni.sportplanet.entity.Location[id=" + locationId
				+ "]";
	}

	// @Override
	// public Object onCycleDetected(Context arg0) {
	// System.out.println("CycleRecoverable.onCycleDetected # ".concat(this
	// .toString()));
	// Location location = new Location();
	// location.setLocationId(this.getLocationId());
	// return location;
	// }

}
